package com.ieasy.module.site.web.action;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ieasy.basic.model.Msg;
import com.ieasy.basic.util.cons.Const;
import com.ieasy.module.common.web.action.BaseController;
import com.ieasy.module.site.service.IColumnService;
import com.ieasy.module.site.web.form.ColumnForm;

@Controller
@RequestMapping("/admin/site/column")
public class ColumnAction extends BaseController {

	@Inject
	private IColumnService columnService ;
	
	@RequestMapping("/col_main_UI.do")
	public String col_main_UI() {
		return Const.SITE + "col_main_UI" ;
	}
	
	@RequestMapping("/col_form_UI.do")
	public String col_form_UI(ColumnForm form, Model model) throws Exception {
		if(null != form.getId() && !"".equals(form.getId())) {
			model.addAttribute("id", form.getId()) ;
		}
		return Const.SITE + "col_form_UI" ;
	}
	
	@RequestMapping("/add.do")
	@ResponseBody
	public Msg add(ColumnForm form) throws Exception {
		Msg msg = this.columnService.add(form) ;
		return msg ;
	}
	
	@RequestMapping("/delete.do")
	@ResponseBody
	public Msg delete(ColumnForm form) throws Exception {
		Msg msg = this.columnService.delete(form) ;
		return msg ;
	}
	
	@RequestMapping("/update.do")
	@ResponseBody
	public Msg update(ColumnForm form) throws Exception {
		Msg msg = this.columnService.update(form) ;
		return msg ;
	}
	
	@RequestMapping("/get.do")
	@ResponseBody
	public ColumnForm get(ColumnForm form) throws Exception {
		return this.columnService.get(form) ;
	}
	
	@RequestMapping("/tree.do")
	@ResponseBody
	public List<ColumnForm> tree(ColumnForm form) throws Exception {
		return this.columnService.tree(form.getPid()) ;
	}
	
	@RequestMapping("/doNotNeedAuth_tree.do")
	@ResponseBody
	public List<ColumnForm> doNotNeedAuth_tree(ColumnForm form) throws Exception {
		return this.columnService.tree(form.getPid()) ;
	}
	
	@RequestMapping("/combo_tree.do")
	@ResponseBody
	public List<ColumnForm> combo_tree(ColumnForm form) throws Exception {
		return this.columnService.combo(form) ;
	}
	
	
	@RequestMapping("/doNotNeedAuth_sort.do")
	@ResponseBody
	public void doNotNeedAuth_sort(int oldSort, int newSort, String id, String pid) {
		this.columnService.updateResetSort(oldSort, newSort, id, pid) ;
	}
	
	@RequestMapping("/doNotNeedAuth_push.do")
	@ResponseBody
	public Msg doNotNeedAuth_push(@RequestParam String id) throws Exception {
		this.columnService.push(id) ;
		return new Msg(true, "操作成功") ;
	}
}
